﻿using System;
using System.Threading;
using MugenInjection.Interface;

namespace MugenInjection.Infrastructure
{
    /// <summary>
    ///     The helper class.
    /// </summary>
    public static class InjectorUtils
    {
        #region Fields

        private static int _globalId;

        /// <summary>
        ///     Contain MugenInjection assembly name with public key.
        /// </summary>
        public static readonly string MugenInjectionAssemblyName =
            "MugenInjection.Core, PublicKey=00240000048000009400000006020000002400005253413100040000010001005515f32c95d7ac72020d117fa0a25b0dc2be6483827ffe624875b838c9e02c43345e566d5159437f1eddf9ae9f16075f1a971394c1d0975b79a553bad5c28af1dbf1e36f5b5b0142918b33a90884e1621ef8bfc2a2433ab406e159cc3ad2ecb792686efaae6a60f7cf69016ca98ee2b0ebf8dcc85f9f0c0e21d22a1827b830aa";

#if !FULLEXPRESSION
        private static IReflectionAccessProvider _reflectionAccessProvider = new EmitReflectionAccessProvider();
#else
        private static IReflectionAccessProvider _reflectionAccessProvider = new ExpressionReflectionAccessProvider()
#if !NETFX_CORE
{
    UseEmitToConvertDelegate = true
}
#endif
;
#endif


        #endregion

        #region Properties

        /// <summary>
        ///     Gets the empty types.
        /// </summary>
        public static readonly Type[] EmptyTypes = new Type[0];

        /// <summary>
        ///     Gets or sets the <see cref="IReflectionAccessProvider" />.
        /// </summary>
        public static IReflectionAccessProvider ReflectionAccessProvider
        {
            get { return _reflectionAccessProvider; }
            set
            {
                Validate.PropertyNotNull(value, "ReflectionAccessProvider");
                _reflectionAccessProvider = value;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Gets the id.
        /// </summary>
        /// <returns>An instance of <see cref="int"/>.</returns>
        public static int GetNextId()
        {
            return Interlocked.Increment(ref _globalId);
        }

        #endregion

    }
}